require 'test/unit/testcase'

module Test
module Unit
  
  class TestCase
    def method_stub(cls, method_name)
      cls_stub = Class.new(cls)
      cls_stub.class_eval do 
        (public_instance_methods(true) + private_instance_methods(true) + protected_instance_methods(true) - (Object.private_instance_methods + Object.public_instance_methods) - [method_name.to_s]).each do |mname|
          define_method mname.to_sym do
            raise RuntimeError.new("unstubbed method invoked: #{mname.to_s}") unless @stub_everything
          end
        end

        def initialize
        end
        
        def stub_everything
          @stub_everything = true
        end

        public method_name
      end
      obj = cls_stub.new
      [obj.method(method_name), obj]
    end
  end
    
end
end